package cn.iocoder.yudao.module.picturebook.controller.admin.postlike;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.picturebook.controller.admin.postlike.vo.*;
import cn.iocoder.yudao.module.picturebook.dal.dataobject.postlike.PostLikeDO;
import cn.iocoder.yudao.module.picturebook.service.postlike.PostLikeService;

@Tag(name = "绘本系统 - 帖子点赞")
@RestController
@RequestMapping("/picturebook/post-like")
@Validated
public class PostLikeController {

    @Resource
    private PostLikeService postLikeService;

    @PostMapping("/create")
    @Operation(summary = "创建帖子点赞")
    @PreAuthorize("@ss.hasPermission('picturebook:post-like:create')")
    public CommonResult<Long> createPostLike(@Valid @RequestBody PostLikeSaveReqVO createReqVO,@RequestHeader("token") Long userId) {
        return success(postLikeService.createPostLike(createReqVO, userId));
    }

    /*@PutMapping("/update")
    @Operation(summary = "更新帖子点赞")
    @PreAuthorize("@ss.hasPermission('picturebook:post-like:update')")
    public CommonResult<Boolean> updatePostLike(@Valid @RequestBody PostLikeSaveReqVO updateReqVO) {
        postLikeService.updatePostLike(updateReqVO);
        return success(true);
    }*/

    @DeleteMapping("/delete")
    @Operation(summary = "删除帖子点赞")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('picturebook:post-like:delete')")
    public CommonResult<Boolean> deletePostLike(@RequestParam("id") Long id) {
        postLikeService.deletePostLike(id);
        return success(true);
    }

   /* @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除帖子点赞")
                @PreAuthorize("@ss.hasPermission('picturebook:post-like:delete')")
    public CommonResult<Boolean> deletePostLikeList(@RequestParam("ids") List<Long> ids) {
        postLikeService.deletePostLikeListByIds(ids);
        return success(true);
    }*/

   /* @GetMapping("/get")
    @Operation(summary = "获得帖子点赞")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('picturebook:post-like:query')")
    public CommonResult<PostLikeRespVO> getPostLike(@RequestParam("id") Long id) {
        PostLikeDO postLike = postLikeService.getPostLike(id);
        return success(BeanUtils.toBean(postLike, PostLikeRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得帖子点赞分页")
    @PreAuthorize("@ss.hasPermission('picturebook:post-like:query')")
    public CommonResult<PageResult<PostLikeRespVO>> getPostLikePage(@Valid PostLikePageReqVO pageReqVO) {
        PageResult<PostLikeDO> pageResult = postLikeService.getPostLikePage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, PostLikeRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出帖子点赞 Excel")
    @PreAuthorize("@ss.hasPermission('picturebook:post-like:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportPostLikeExcel(@Valid PostLikePageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<PostLikeDO> list = postLikeService.getPostLikePage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "帖子点赞.xls", "数据", PostLikeRespVO.class,
                        BeanUtils.toBean(list, PostLikeRespVO.class));
    }*/

}